// index.js

import {
  BASE_API
} from "../../../utils/config";
Page({
  data: {
    baseUrl: BASE_API,
    popupLoginVisible: false,
    tempNickName: '',
    tempAvatarUrl: 'https://thirdwx.qlogo.cn/mmopen/vi_32/POgEwh4mIHO4nibH0KlMECNjjGxQUq24ZEaGT4poC6icRiccVGKSyXwibcPq4BWmiaIGuG1icwxaQX6grC9VemZoJ8rg/132',
  },

  
 savaAvatarUrl(e){
   let that = this
    return new Promise((resolve, reject) => {
      wx.uploadFile({
        url: that.data.baseUrl + '/uploadAvatar',
        name: 'avatarUrl',
        filePath: this.data.tempAvatarUrl,
        header: {
          'content-type': ' multipart/form-data',
        },
        success: res => {
          console.log("服务器保存头像的位置:"+res.data)
          this.setData({
            tempAvatarUrl:res.data,
          })

        },  
        fail: res => {
          wx.showToast({
            title: '上传失败',
            icon: 'none',
            duration: 2000,
          })
        }
      })
    })
   },
     

  /**
   * 输入框
   */
  onInput(e){
    console.log(e)
    let  nickName  = e.detail.value
    console.log("==当前昵称:"+nickName)
      this.setData({
        tempNickName : nickName
      })
      
    },

    onChooseAvatar(e) {
      let tempAvatarUrl = e.detail.avatarUrl
      this.setData({
        tempAvatarUrl
      })
      console.log("=更新后头像："+this.data.tempAvatarUrl)
    },


    showLogin(e){
      this.setData({
        popupLoginVisible:true,
      })
    },

    setLogin(e){
      this.setData({
        popupLoginVisible:false,
      })
      this.savaAvatarUrl()
    },



});
